package com.kafka.service;

import com.kafka.utils.HttpClientUtil;
import com.kafka.utils.MessageDigestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.*;

@Component
public class ApiService_Test {

    private static Logger logger = LoggerFactory.getLogger(ApiService_Test.class);

    @Value("${aids.dyn}")
    private  String aidsDynUrl;

    @Value("${aids.sta}")
    private  String aidsStaUrl;

    @Value("${aids.water}")
    private  String aidsWaterUrl;

    /**
     * @Description 查询所有航标的静态数据
     */
    public String getAllBuoyInfo() {

        List<String> list = new ArrayList<String>();
        //list.add("name=#253红浮");
        list.add("1528");
        //list.add("timeStamp=" + System.currentTimeMillis());
        //String url = ascSort(aidsStaUrl, list);
        String url=aidsStaUrl+"1528";
        //url = url.replaceAll("#","%23");
        System.out.println(url);
        String str = HttpClientUtil.httpRequest(url,"GET");
        System.out.println(str);

        return str;

    }

    /**
     * @Description 查询所有航标的动态数据
     */
    public String getAllBuoyDyn() {

        List<String> list = new ArrayList<String>();
        list.add("3177");
        //list.add("timeStamp=" + System.currentTimeMillis());
        //String url = ascSort(aidsStaUrl, list);
        String url=aidsDynUrl+"3177";
        System.out.println(url);
        String str = HttpClientUtil.httpRequest(url, "GET");
        System.out.println(str);

        return str;
    }

    /**
     * @Description 查询所有水位监测点的动态数据
     */
    public String getAllWaterStationDyn() {

        List<String> list = new ArrayList<String>();
        /*list.add("organizationId=100001");
        list.add("timeStamp=" + System.currentTimeMillis());
        String url = ascSort(aidsWaterUrl, list);*/
        String url=aidsWaterUrl+"3941";
        System.out.println(url);
        String str = HttpClientUtil.httpRequest(url, "GET");
        System.out.println(str);

        return str;
    }

    public String ascSort(String str, List<String> lists) {

        List<String> list = new ArrayList<String>(lists);
        Collections.sort(list);
        StringBuffer sbf = new StringBuffer(str);
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            buffer.append(list.get(i) + "&");
        }
        String param = buffer.toString();
        String sign = MessageDigestUtil.MD5(param.substring(0, param.length() - 1) + "C38568FF5709EDBEFF9F6EC9373069F8").toUpperCase();
        sbf.append(param + "sign=" + sign).toString();

        return sbf.toString();

    }

}